package cc.wsyw126.java.nowcoder.offerdidi;

import java.util.Scanner;

/**
 * Created by dp on 17/3/30.
 */
public class didi1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        while (sc.hasNext()) {
            String s1 = sc.nextLine();
            n = Integer.valueOf(s1);
            if (n == 0) continue;
            String s = sc.nextLine();
            String[] split = s.split(" ");
            int left1 = 0, right1 = 0, left2 = -1, right2 = -1;
            int leftValue = Integer.valueOf(split[0]);
            for (int i = 1; i < n; i++) {
                if (leftValue > Integer.valueOf(split[i])) {
                    leftValue = Integer.valueOf(split[i]);
                    left1 = i;
                } else {
                    break;
                }
            }
            boolean flag = false;
            for (int i = left1 + 1; i < n; i++) {
                if (leftValue < Integer.valueOf(split[i])) {
                    if (flag) {
                        right1 = i - 1;
                        if (right1 - left1 > right2 - left2) {
                            left2 = left1;
                            right2 = right1;
                            flag = false;
                            left1 = right1;
                        }
                    }
                    leftValue = Integer.valueOf(split[i]);
                } else {
                    flag = true;
                    leftValue = Integer.valueOf(split[i]);
                    if (i == n - 1) {
                        right1 = i;
                        if (right1 - left1 > right2 - left2) {
                            left2 = left1;
                            right2 = right1;
                        }
                    }
                }
            }
            System.out.println(left2 + " " + right2);
        }
    }
}
